package com.levi.juc.pool;

import java.util.concurrent.*;

/**
 * @author shentong
 * @since 2023/2/10 22:02
 * 模拟线程池使用不当导致死锁
 * 父任务和子任务使用同一个线程池
 */
public class MainTest {
    static ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 3, TimeUnit.SECONDS, new LinkedBlockingDeque<>(10), new NamingThreadFactory("customThreadpool"));

    public static void main(String[] args) {
        Task task = new Task();
        executor.execute(task::execute);
        executor.shutdown();
    }
    static class Task implements Runnable{

        private void execute() {
            executor.execute(()-> System.out.println("子任务执行"+"线程名称"+Thread.currentThread().getName()));

        }

        @Override
        public void run() {
            execute();
        }
    }
}
